﻿using UnityEngine;
using System.Collections;
using LuaInterface;

public class LuaTrigger2D : MonoBehaviour {

    LuaTable table;

    protected LuaFunction enterFunc;
    protected LuaFunction exitFunc;

    public void SetEnterFunc(LuaFunction func  ,LuaTable tb)
    {
        enterFunc = func;
        table = tb;
    }
    public void SetExitFunc(LuaFunction func, LuaTable tb = null)
    {
        exitFunc = func;
        table = tb;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(enterFunc!=null)
        {
            if(table!=null)
                enterFunc.Call(table,collision);
            else
                enterFunc.Call(collision);
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (exitFunc != null)
        {
            if (table != null)
                exitFunc.Call(table, collision);
            else
                exitFunc.Call(collision);
        }
    }
}
